package com.xyht.sca_s.student_manage_system.modules.goods.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.goods.entity.req.SmsGoodsClassificationAddReq;
import com.xyht.sca_s.student_manage_system.modules.goods.entity.req.SmsGoodsClassificationDeletedReq;
import com.xyht.sca_s.student_manage_system.modules.goods.entity.req.SmsGoodsClassificationUpdateReq;
import com.xyht.sca_s.student_manage_system.modules.goods.service.SmsGoodsClassificationService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 物品分类表(--迎新) 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-01-17
 */
@RestController
@SecretBody
@RequestMapping("/goods/classification")
public class SmsGoodsClassificationController {

    @Resource
    private SmsGoodsClassificationService smsGoodsClassificationService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiOperation("添加物品分类")
    @PostMapping("/add")
    public ResponseResult addGoodsClassification(HttpServletRequest request, @RequestBody SmsGoodsClassificationAddReq addReq){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsGoodsClassificationService.addGoodsClassification(userId,addReq);
    }

    @ApiOperation("删除物品分类")
    @PostMapping("/deleted")
    public ResponseResult deletedGoodsClassification(@RequestBody SmsGoodsClassificationDeletedReq deletedReq){
        return smsGoodsClassificationService.deletedGoodsClassification(deletedReq);
    }

    @ApiOperation("修改物品分类")
    @PostMapping("/update")
    public ResponseResult updateGoodsClassification(@RequestBody SmsGoodsClassificationUpdateReq updateReq){
        return smsGoodsClassificationService.updateGoodsClassification(updateReq);
    }

    @ApiOperation("物品分类列表")
    @GetMapping("/list")
    public ResponseResult getGoodsClassificationList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                     @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                     @RequestParam(value = "name", required = false) String name,
                                                     @RequestParam(value = "classificationId", required = false) String classificationId,
                                                     @RequestParam(value = "isOn", required = false) Integer isOn) {
        return smsGoodsClassificationService.getGoodsClassificationList(pageNum,pageSize,name,classificationId,isOn);
    }

}

